{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "乐学偶得版权所有 lexueoude.com 公众号：乐学Fintech"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "/*This program is a little calculator*/\n",
    "#include<stdio.h>\n",
    "\n",
    "int main(void)\n",
    "{\n",
    "    float weight;/*你想买多少斤的肉？*/\n",
    "    float price;/*你买的所有猪肉的价格多少*/\n",
    "    \n",
    "    printf(\"这猪肉多少钱啊？\\n\");\n",
    "    printf(\"哦哦，欢迎光临，让我看看啊！\\n\");\n",
    "    printf(\"请把你要买的猪肉放秤上吧：\");\n",
    "    \n",
    "    /*用scanf获取用户的输入*/\n",
    "    scanf(\"%f\",&weight);\n",
    "    \n",
    "    price=weight*99.9999;\n",
    "    printf(\"客观您好，您的猪肉已经帮您称好了\\n\");\n",
    "    printf(\"你现在需要付我 $%.2f. \\n\",price);\n",
    "    printf(\"老板，您太黑了吧，你开的难道是黑店？\");\n",
    "    \n",
    "    return 0;\n",
    "}\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "data: variables变量 constants常量\n",
    "\n",
    "bits bytes words\n",
    "bit 最小的储存单位01\n",
    "bytes 8 bits\n",
    "8-bit 16-bits 32-bits 64-bits words"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "integer (整型整数)：123，-123，2，8\n",
    "float(浮点型小数)：123.0，-123.0，2.8，8.2\n",
    "\n",
    "storage(储存方式不一样)\n",
    "\n",
    "integer: 8-bit -------- example: 7 00000111 $   2^2 + 2^1 + 2^0=7$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "float:7.0 0.7E1 =$0.7*10^1$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "/*This program is a little calculator*/\n",
    "#include<stdio.h>\n",
    "\n",
    "int main(void)\n",
    "{\n",
    "    int weight=1,price;/*你想买多少斤的肉？declaring variable and initializing variable*/\n",
    "    /*你买的所有猪肉的价格多少*/\n",
    "    \n",
    "    printf(\"这猪肉多少钱啊？\\n\");\n",
    "    printf(\"哦哦，欢迎光临，让我看看啊！\\n\");\n",
    "    printf(\"请把你要买的猪肉放秤上吧：\");\n",
    "\n",
    "    \n",
    "    price=weight*1;\n",
    "    printf(\"客观您好，您的猪肉已经帮您称好了\\n\");\n",
    "    printf(\"你现在需要付我 $%d. \\n\",price);\n",
    "    printf(\"老板，您太黑了吧，你开的难道是黑店？\");\n",
    "    \n",
    "    return 0;\n",
    "}\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "print format\n",
    " \n",
    "%----place holder 占位\n",
    "%s string \n",
    "%d int\n",
    "%f"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "octal(base 8)\n",
    "hexadecimal(base 16)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#include<stdio.h>\n",
    "\n",
    "int main(void)\n",
    "{\n",
    "    int num=100;\n",
    "    \n",
    "    printf(\"octal=%#o;dec=%d;hex=%#x\",num,num,num);\n",
    "    \n",
    "    return 0;\n",
    "}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "signed type:\n",
    "short int\n",
    "long int \n",
    "long long int C99:long long(64 bit) \n",
    "\n",
    "\n",
    "unsigned type:\n",
    "unsigned (nonnegetive)\n",
    "unsigned long int/ unsigned long unsigned short int"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2147483647 -2147483648 -2147483647"
     ]
    }
   ],
   "source": [
    "#include<stdio.h>\n",
    "\n",
    "int main(void)\n",
    "{\n",
    "    int num=2147483647;\n",
    "    \n",
    "    printf(\"%d %d %d\",num,num+1,num+2);\n",
    "    \n",
    "    return 0;\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "char char_1;\n",
    "\n",
    "char_1='a';\n",
    "char_1=\"William\"; /*string*/"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "number :1,000,000,000,\n",
    "scientific notation: 1.0*10^9\n",
    "CS: 1.0e9"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "This is a big num 123456790519087104.000000 which is the same as 1.234568e+17"
     ]
    }
   ],
   "source": [
    "#include<stdio.h>\n",
    "\n",
    "int main(void)\n",
    "{\n",
    "    float num=123456789876543212.00;\n",
    "    \n",
    "    printf(\"This is a big num %f which is the same as %e\",num,num);\n",
    "    \n",
    "    return 0;\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "This is a big num 8.000000 which is the same as 8.000000e+00"
     ]
    }
   ],
   "source": [
    "#include<stdio.h>\n",
    "\n",
    "int main(void)\n",
    "{\n",
    "    float x,y,z;\n",
    "    x=1.0e2;\n",
    "    y=-1.0e2+8;\n",
    "    z=x+y;\n",
    "    \n",
    "    printf(\"This is a big num %f which is the same as %e\",z,z);\n",
    "    \n",
    "    return 0;\n",
    "}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "类型大小判断"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "int have size of 4 \n",
      "float have size of 4 \n",
      "char have size of 1 \n",
      "long have size of 8 \n",
      "long long have size of 8 \n",
      "double have size of 8 \n"
     ]
    }
   ],
   "source": [
    "#include<stdio.h>\n",
    "\n",
    "int main(void)\n",
    "{\n",
    "    \n",
    "    printf(\"int have size of %zd \\n\",sizeof(int));\n",
    "    printf(\"float have size of %zd \\n\",sizeof(float));\n",
    "    printf(\"char have size of %zd \\n\",sizeof(char));\n",
    "    printf(\"long have size of %zd \\n\",sizeof(long));\n",
    "    printf(\"long long have size of %zd \\n\",sizeof(long long));\n",
    "    printf(\"double have size of %lu \\n\",sizeof(double));\n",
    "    return 0;\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007int have size of 4 \n",
      "float have size of 4 \n",
      "char have size of 1 \n",
      "long have size of 8 \n",
      "long long have size of 8 \n",
      "double have size of 8 \n"
     ]
    }
   ],
   "source": [
    "#include<stdio.h>\n",
    "\n",
    "int main(void)\n",
    "{\n",
    "    \n",
    "    printf(\"\\a\\a\\a\\a\\a\\a\\a\\a\\a\\aint have size of %zd \\n\",sizeof(int));\n",
    "    printf(\"float have size of %zd \\n\",sizeof(float));\n",
    "    printf(\"char have size of %zd \\n\",sizeof(char));\n",
    "    printf(\"long have size of %zd \\n\",sizeof(long));\n",
    "    printf(\"long long have size of %zd \\n\",sizeof(long long));\n",
    "    printf(\"double have size of %lu \\n\",sizeof(double));\n",
    "    return 0;\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "C",
   "language": "c",
   "name": "c"
  },
  "language_info": {
   "file_extension": ".c",
   "mimetype": "text/plain",
   "name": "c"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
